<?php
if (!defined('INPOL')) return2();
$parse=$Lang;
$parse['page']=$page;
$parse['action']='view';
$parse['empty_selected']='';
$parse['button_lang']=$Lang['edit'];
$parse['button_click']='Redirect(\'?p='.$page.'&amp;a=edit&amp;id='.$id.'\');';
$parse['selects_disabled']=' disabled="disabled"';
//$parse['selects_disabled']='';
$parse['nr_value']=$pol['nr'];
$parse['add_nr_value']=$pol['add_nr'];
$parse['pol_attr_checked']=$pol['client_attraction']=='Y'?' checked="checked"':'';
//$parse['pol_canc_checked']=$pol[''];
$parse['pol_canc_checked']='';
$parse['prev_pol_disabled']=' disabled="disabled"';
$parse['prev_pol_value']=$pol['prev_nr'];
$parse['cta_premium_value']=$pol['cta_premium'];
$parse['ng_premium_value']=$pol['ng_premium'];
$parse['riska_class_value']=$pol['octa_risks'];
$parse['issue_date_value']=$pol['issue_date'];
$parse['date_from_value']=$pol['from_date'];
$parse['date_from_time_value']=$pol['from_time'];
$parse['date_to_value']=$pol['to_date'];
$parse['payment_count_value']=$pol['payment_count'];
$parse['payment_none_selected']='';
$parse['payment_cash_selected']='';
$parse['payment_transfer_selected']='';
switch($pol['payment_type'])
{
    case '':
    case 0:
    case '0':
        $parse['payment_none_selected']=' selected="selected"';
    break;
    case '1':
    case 1:
        $parse['payment_cash_selected']=' selected="selected"';
    break;
    case '2':
    case 2:
        $parse['payment_transfer_selected']=' selected="selected"';
    break;
}
$parse['ins_sum_value']=$pol['ins_sum'];
$parse['ins_prem_value']=$pol['ins_prem'];
$parse['commision_perc_value']=$pol['comm_rate'];
$parse['broker_perc_value']=$pol['broker_rate'];
$parse['discount_perc_value']=$pol['add_disc_rate'];
$parse['comment_value']=$pol['comment'];
$parse['ins_type_update_check_db']='false';

$objects=$sql->query("SELECT objects.id as oId, object_type.id as tId, objects.loc, objects.cta_person, objects.`desc`, objects.reg_nr, objects.manufacturer, objects.model FROM pol_obj, objects, object_type WHERE pol_obj.oId = objects.id AND objects.tId = object_type.id AND pol_obj.pId = '$id' LIMIT 2;");
$i=1;
$obj_t1=0;
$obj_t2=0;
while($object=$sql->fetch_array($objects))
{
    $desc=($object['tId']!=getConfig('settings','transport_id', '1'))?''.$object['loc'].' | '.$object['cta_person'].' | '.$object['desc']:$object['reg_nr'].' | '.$object['manufacturer'].' | '.$object['model'];
    $parse['object'.$i.'']='<option value="'.$object['oId'].'" selected="selected">'.$desc.'</option>';
    if($i==1)$obj_t1=$object['tId'];else$obj_t2=$object['tId'];
    $parse['obj_types'.$i.'']='';
    $i++;
}
$obj_types=$sql->query("SELECT id, `name` FROM object_type;");

while($obj_type=$sql->fetch_array($obj_types))
{
    $sel=$obj_t1==$obj_type['id']?' selected="selected"':'';
    $parse['obj_types1'].='<option value="'.$obj_type['id'].'"'.$sel.'>'.$obj_type['name'].'</option>';
}
$sql->reset_query($obj_types);
while($obj_type=$sql->fetch_array($obj_types))
{
    $sel=$obj_t2==$obj_type['id']?' selected="selected"':'';
    $parse['obj_types2'].='<option value="'.$obj_type['id'].'"'.$sel.'>'.$obj_type['name'].'</option>';
}

$parse['payment_button']='<input type="button" class="yt_button" value="'.$Lang['view_payments'].'" onclick="openWindow(\'?p=payments&amp;no_head&amp;a=view&amp;id='.$id.'\', \'payments\', 700, 400);" />';
$parse['init_js']='initEditPolicy();';
$parse['comment_readonly']=' readonly="readonly"';
$tqry=$sql->query("SELECT id, name, abbr FROM insurance_companies WHERE id='{$pol['ins_comp_id']}';");
$otype=$sql->fetch_array($tqry);
$parse['ins_comps']='<option value="'.$otype['id'].'" selected="selected">'.$otype['abbr'].'</option>';
    
$iqry=$sql->query("SELECT id, name FROM ins_type WHERE id='{$pol['ins_type_id']}';");
$ins_type=$sql->fetch_array($iqry);
$parse['ins_types']='<option value="'.$ins_type['id'].'" selected="selected">'.$ins_type['name'].'</option>';
    
$iqry=$sql->query("SELECT id, name FROM pol_status WHERE id='{$pol['state_id']}'");
$ins_type=$sql->fetch_array($iqry);
$parse['statuses']='<option value="'.$ins_type['id'].'" selected="selected">'.$ins_type['name'].'</option>';
    
$tqry=$sql->query("SELECT id, name, code, address FROM clients WHERE id='{$pol['taker_id']}';");
$taker=$sql->fetch_array($tqry);
$taker['name']=str_replace("&","&amp;", $taker['name']);
$parse['takers']='<option value="'.$taker['id'].'" selected="selected">'.$taker['name'].' | '.$taker['code'].' | '.$taker['address'].'</option>';

if($pol['owner_id']!='' && $pol['owner_id']!=0)
{
    $tqry=$sql->query("SELECT id, name, code, address FROM clients WHERE id='{$pol['owner_id']}';");
    $owner=$sql->fetch_array($tqry);
    $owner['name']=str_replace("&","&amp;", $owner['name']);
    $parse['owners']='<option value="'.$owner['id'].'" selected="selected">'.$owner['name'].' | '.$owner['code'].' | '.$owner['address'].'</option>';
}
if($pol['subscriber_id']!='' && $pol['subscriber_id']!=0)
{
    $tqry=$sql->query("SELECT id, name, code, address FROM clients WHERE id='{$pol['subscriber_id']}';");
    $subs=$sql->fetch_array($tqry);
    $subs['name']=str_replace("&","&amp;", $subs['name']);
    $parse['subscribers']='<option value="'.$subs['id'].'" selected="selected">'.$subs['name'].' | '.$subs['code'].' | '.$subs['address'].'</option>';
}
if($pol['octa_code_id']!='' && $pol['octa_code_id']!=0)
{
    $octa_codes_qry=$sql->query("SELECT id, code, name FROM octa_codes WHERE id='{$pol['octa_code_id']}'");
    $tl_codes=$sql->fetch_array($octa_codes_qry);
    $parse['tl_codes']='<option value="'.$tl_codes['id'].'" selected="selected">'.$tl_codes['code'].' | '.$tl_codes['name'].'</option>';
}
$octa_exmpl_qry=$sql->query("SELECT id,code, name FROM octa_examples WHERE id='{$pol['octa_example_id']}';");
$exmpl=$sql->fetch_array($octa_exmpl_qry);
$parse['octa_examples']= '<option value="'.$exmpl['id'].'" selected="selected">'.$exmpl['code'].' | '.$exmpl['name'].'</option>';
    
$octa_dsc_qry=$sql->query("SELECT id,code, name FROM octa_discounts WHERE id='{$pol['octa_discount_id']}';");
$dsc=$sql->fetch_array();
$parse['octa_discountss']= '<option value="'.$dsc['id'].'" selected="selected">'.$dsc['code'].' | '.$dsc['name'].'</option>';

if($pol['validity_territory_id']!=0)
{
    $valtqry=$sql->query("SELECT id, name FROM validity_territory WHERE id='{$pol['validity_territory_id']}';");
    $terr=$sql->fetch_array($valtqry);
    $parse['val_territories']= '<option value="'.$terr['id'].'" selected="selected">'.$terr['name'].'</option>';
}
           
$curr_qry=$sql->query("SELECT id, name FROM currency WHERE id='{$pol['currency_id']}'");
$curr=$sql->fetch_array($curr_qry);
$parse['currencies']= '<option value="'.$curr['id'].'" selected="selected">'.$curr['name'].'</option>';
    
$brokers=$sql->query("SELECT id, name FROM brokers WHERE id='{$pol['broker_id']}'");
$broker=$sql->fetch_array($brokers);
$parse['brokers']= '<option value="'.$broker['id'].'" selected="selected">'.$broker['name'].'</option>';
    
$emp_qry=$sql->query("SELECT id, name, user FROM employees WHERE id='{$pol['employee_id']}'");
$emp=$sql->fetch_array($emp_qry);
$parse['employees']= '<option value="'.$emp['id'].'" selected="selected">'.$emp['name'].'</option>';
    
$tpl->parsetemplate('policies',$parse);
?>